package com.zmn.brs.factory;

import com.google.common.collect.Maps;
import com.zmn.brs.services.interfaces.IParseFunction;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * 类描述：功能解析工厂
 *
 * @author xujie
 * @since 2021/03/12 14:13
 */
public class ParseFunctionFactory {

    private final Map<String, IParseFunction> functionMap;

    public ParseFunctionFactory(List<IParseFunction> parseFunctions) {

        functionMap = Maps.newHashMap();
        if (CollectionUtils.isEmpty(parseFunctions)) {
            return;
        }
        for (IParseFunction parseFunction : parseFunctions) {
            if (StringUtils.isEmpty(parseFunction.functionName())) {
                continue;
            }
            functionMap.put(parseFunction.functionName(), parseFunction);
        }
    }

    public IParseFunction getFunction(String functionName) {

        return functionMap.get(functionName);
    }
}
